package com.yjhb.android.sbz.v2.mvp.presenter

import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONArray
import com.alibaba.fastjson.JSONObject
import com.yjhb.android.sbz.http.HttpObserver
import com.yjhb.android.sbz.http.HttpTool
import com.yjhb.android.sbz.v2.mvp.V2ConventionPresenter
import com.yjhb.android.sbz.v2.mvp.view.ConfigView
import com.jojo.android.zxlib.tool.ZxLogTool


/**
 *  创建者 zx
 *  创建时间 2021/5/20 10:35
 */
class ConfigPresenter(view: ConfigView) : V2ConventionPresenter<ConfigView>(view) {


    fun getSysConfig(type: String) {
        model?.let {
            HttpTool.request(model.getSystemConfig(type), object : HttpObserver<JSON?>() {
                override fun onResult(data: JSON?) {
                    if (data is JSONObject) {
                        view?.onConfig(data)
                    } else if (data is JSONArray) {
                        view?.onConfig(data)
                    }
                }

                override fun onError(code: Int, msg: String?) {
                    ZxLogTool.e(msg)
                    view?.onFailure(code, msg)
                }
            })
        }
    }

}